package testcase.app;

import java.io.File;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.app.ApiUploadPicforFeedback;
import common.Host;
import common.ImageOperation;
import common.TestData;

/**
 * 帮忙医APP上传意见图片ApiUploadPicforFeedback接口测试用例
 * @author lipeng
 *
 */
public class TestApiUploadPicforFeedback
{
	/**
	 * 帮忙医APP上传意见图片ApiUploadPicforFeedback接口测试环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */
  @DataProvider(name="Test")
  public static String[][] testApiUploadPicforFeedbackDataProvider() throws Exception{
	  Host.setup("Test");
	  TestData td =new TestData("app/TestApiUploadPicforFeedback.xml");
	  return td.getParam();
}  
  /**
   * 帮忙医APP上传意见图片ApiUploadPicforFeedback接口
   * @param caseName   -用例名称
   * @param array      -意见图片
   * @throws Exception
   */
  @Test(dataProvider="Test",groups={"Test"})
  public void testApiUploadPicforFeedbackTestCase(String caseName,String array)throws Exception{
	  
	  String result = null;
      if(!array.isEmpty()){
 			    //获取图片base64编码字符串
  			String photoPath =System.getProperty("user.dir")
  					+ File.separator + "resources"
  					+ File.separator + "image"
  					+ File.separator + array;
  			String base64photo = ImageOperation.base64Encode(photoPath);
  		
  		    //调用接口并将接口返回数据转换成json格式
  			result = ApiUploadPicforFeedback.post(base64photo);
      }
  		else {
			result = ApiUploadPicforFeedback.post(null);
		}
  		
  		JSONObject jsonResult;
		if (result==null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}
		
  		//设置检查点
  		switch (caseName)
		{
			case "Success":
				Assert.assertEquals(jsonResult.getString("Message"),"上传成功");
				break;
			case "Differentformat1":
				Assert.assertEquals(jsonResult.getString("Message"),"上传成功");
				break;
			case "Differentformat2":
				Assert.assertEquals(jsonResult.getString("Message"),"上传成功");
				break;
			default:
				break;
		}
    }
}
